<template>
  <div id="text" style="margin: 20px">
    <div>默认渲染</div>
    <LazyImage class="imageBox1" img-src="https://i.pinimg.com/736x/2c/eb/20/2ceb200efe2f651d0bca8a5e77e7c68b.jpg" ></LazyImage>

    <hr style="margin: 20px 0px" />

    <div>
      动态设置 -- 
      <button @click="changeAvatar">切换查看图片效果</button>
    </div>
    <LazyImage class="imageBox" :img-src="avatar"></LazyImage>

    <div style="margin-top: 20px">自定义渲染</div>
    <LazyImage class="imageBox" :img-src="avatar">
      <div class="my-slot-main">自定义</div>
    </LazyImage>

  </div>
</template>
  
<script setup>
import { ref, onMounted } from "vue";
import LazyImage from "@/views/test/LazyImage.vue";

const avatar1 =
  "https://i.pinimg.com/736x/22/a9/df/22a9df805d5eb9d602adfd73edbe3b6c.jpg";
const avatar2 =
  "https://i.pinimg.com/736x/22/a9/df/22a9df805d5eb9d602adfd73edbe3b6c_xxx.jpg";

const avatar = ref("");

const changeAvatar = () => {
  avatar.value = avatar.value == avatar1 ? avatar2 : avatar1;
};
onMounted(() => {
  avatar.value = avatar2;
});
</script>

<style lang="scss" scoped>
.imageBox1 {
  width: 80px;
  height: 80px;
  border: 1px solid skyblue;
  box-sizing: border-box;
  margin-top: 10px;
}
.imageBox {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  margin-top: 10px;
}
.my-slot-main {
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  background: yellow;
}
</style>